﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace xiangmu1
{
    public partial class H_Y_TJ : Form
    {
        public H_Y_TJ()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            huiyuanleixing();
            Random r = new Random();
            int i=r.Next(10000, 999999);
            this.label2.Text = i.ToString();
        }
        public void huiyuanleixing()
        {
            string sql = "select * from VipType";
            DataTable dt = FrmHotel.DBHelper.SelectForTable(sql);
            cbo_huiyuanleixing.DisplayMember = "TypeName";
            cbo_huiyuanleixing.ValueMember = "VipId";
            cbo_huiyuanleixing.DataSource = dt;
        }

        private void txt_huiyuanshenfenzheng_TextChanged(object sender, EventArgs e)
        {
           
        }

        private void txt_huiyuandianhua_TextChanged(object sender, EventArgs e)
        {
           
        }

        private void button1_Click(object sender, EventArgs e)
        {

            string kahao = this.label2.Text;
            string name = txt_huiyuanxingming.Text;
            
            string sex = string.Empty;
            sex = radioButton1.Checked == true ? "男" : "女";
            string shenfenzheng = dateTimePicker1.Text;
            int huiyuanleixing = Convert.ToInt32(cbo_huiyuanleixing.SelectedValue);
            string Money = txt_huiyuankajine.Text;
            string phone = txt_huiyuandianhua.Text;
            if (string.IsNullOrEmpty(kahao) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(shenfenzheng) || string.IsNullOrEmpty(phone) || string.IsNullOrEmpty(Money))
            {
                MessageBox.Show("请填写完整信息", "提示窗口");
                return;
            }


            string chaxunkahao = string.Format("select Count(1) from VipInfo where VpKaHao='{0}'",this.label2.Text);
            int shu1 = Convert.ToInt32(FrmHotel.DBHelper.SelectOne(chaxunkahao));
            if (shu1 > 0)
            {
                MessageBox.Show("此账号已拥有不可以重复");
                return;
            }
            string sql = string.Format(@"insert into VipInfo values('{0}','{1}','{2}','{3}',{4},{5},'{6}',getdate(),0);",
                           name, kahao, phone , sex,  huiyuanleixing, Money,shenfenzheng);
            int hang = FrmHotel.DBHelper.ExecuteUpdate(sql);
            if (hang > 0)
            {
                MessageBox.Show("添加成功");
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show("添加失败,请核对信息添加");
            }
        }

        private void txt_huiyuankahao_TextChanged(object sender, EventArgs e)
        {
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void label4_Click(object sender, EventArgs e)
        {


        }

        private void button3_Click(object sender, EventArgs e)
        {
            Random r = new Random();
            int i = r.Next(10000, 999999);
            this.label2.Text = i.ToString();
        }
    }
}
